package com.zx.controller;/*
 *@program:SSM
 *@author: zhangjian
 *@Time: 2021/7/27  9:11
 */

import com.zx.entity.Funds;
import com.zx.entity.Project;
import com.zx.service.FundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller
public class FundController {

    @Autowired
    private FundService fundService;


    /**
     *查询待申请列表
     */
    @ResponseBody
    @RequestMapping("/findDai")
    public List findDai(){
        List<Funds> list = fundService.findDai();
        return list;
    }

    /**
     *查询已申请列表
     */
    @ResponseBody
    @RequestMapping("/findYi")
    public List findYi(){
        List<Funds> list = fundService.findYi();
        return list;
    }


    /**
     * 申请经费
     */
    @RequestMapping("/addFund")
    public String addFund(Funds funds){
        fundService.addFund(funds);
        return "redirect:index.jsp";
    }

    @InitBinder
    public void initData(WebDataBinder wdb){
        wdb.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
    }


    /**
     * 更新状态为申请
     */
    @RequestMapping("/updateFund")
    public String updateFund(Integer pid){
        fundService.updateFund(pid);
        return "redirect:index.jsp";
    }

    /**
     * 删除申请
     */
    @RequestMapping(value = "/deleteFund",method = RequestMethod.POST)
    @ResponseBody
    public String deleteFund(Integer pid){
        fundService.deleteFund(pid);
        return "redirect:index.jsp";
    }

    /**
     *查询已通过列表
     */
    @ResponseBody
    @RequestMapping("/findTong")
    public List findTong(){
        List<Funds> list = fundService.findTong();
        return list;
    }
}
